/****************************************************************************
 * 2025.9 阿桑的笔记本
 ****************************************************************************/

using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using QFramework;

namespace QFramework.Example
{
	public partial class DataSavePanel : UIElement,ICanDataProcessor
	{
		private void Awake()
		{
            BtnClicks();

        }

		protected override void OnBeforeDestroy()
		{
		}

        public override void BtnClicks()
        {
            base.BtnClicks();

            ///保存的逻辑
            SaveJsonBtn.onClick.AddListener(() =>
            {
                Save();
            });

            ///不保存的逻辑
            NoSave.onClick.AddListener(() =>
            {
                NotSave();
            });
        }

        //不管是否存储 都把数值调整到环境配置文件里，所以需要调用SaveSystemData



        public void Save()
        {
            //先验证是否有不合法内容
            SetGameValue();
            FreePlayDataManager.Instance.SetAllDatasInGameModels(FreePlayDataManager.
                Instance.gameModel.gameScence.ZeroDistances,
                new Vector3(FreePlayDataManager.Instance.gameModel.gameScence.WindSpeedX,
                FreePlayDataManager.Instance.gameModel.gameScence.WindSpeedY,
                FreePlayDataManager.Instance.gameModel.gameScence.WindSpeedZ),
                FreePlayDataManager.Instance.gameModel.gameScence.AirRestance,
                float.Parse(surroundingsPlanes.GravityFiled.text),
                float.Parse(surroundingsPlanes.TemperatureFiled.text),
                float.Parse(surroundingsPlanes.AirPressureFiled.text)
                );

            Time.timeScale = 1;
            UIKit.CloseAllPanel();
            
            //this.Hide();
           
        }

        public void NotSave()
        {

            SetGameValue();
            SaveSystemData();
            Time.timeScale = 1;
            UIKit.CloseAllPanel();
        }

        public void SaveSystemData()
        {
            FreePlayDataManager.Instance.SetAllDatasInSpObjs_InFree();

            //throw new NotImplementedException();
        }

        /// <summary>
        /// 把数值修改给到当前场景的环境变量和子弹变量配置文件
        /// </summary>
        void SetGameValue()
        {
            surroundingsPlanes.CheckInputFiledText();
        }
    }
}